package com.example.demo1.pay.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.demo1.pay.entity.OrderPayLog;
import com.example.demo1.pay.mapper.OrderPayLogMapper;
import com.example.demo1.pay.service.OrderPayLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 * 订单支付表 服务实现类
 * </p>
 *
 * @author gong
 * @since 2023-02-27
 */
@Service
public class OrderPayLogServiceImpl extends ServiceImpl<OrderPayLogMapper, OrderPayLog> implements OrderPayLogService {

    @Override
    public int addOrderPayLog(String serialNumber, String payerWalletId, String payeeWalletId, BigDecimal money, String status) {
        OrderPayLog orderPayLog = new OrderPayLog();
        orderPayLog.setSerialNumber(serialNumber);
        orderPayLog.setPayerFundAccount(payerWalletId);
        orderPayLog.setPayeeFundAccount(payeeWalletId);
        orderPayLog.setAmount(money);
        orderPayLog.setStatus(status);
        return this.baseMapper.insert(orderPayLog);
    }

    @Override
    public int refundSerialNumber(String serialNumber, BigDecimal money) {
        OrderPayLog orderPayLog = new OrderPayLog();
        orderPayLog.setStatus("refund");
        orderPayLog.setRefundAmount(money);
        return this.baseMapper.update(orderPayLog, new UpdateWrapper<OrderPayLog>().eq("serial_number", serialNumber));
    }
}
